/*$(document).ready(function() {
	
	$('#commentment').autosize();

	});*/

	
function hideshow(targetid)
{
	var targetid = targetid;
	$('#' + targetid).toggle(400);
}
	  
function commentclick(containerco, responseconid, collabcode, myavatar, userid, namefull)
{
	var containerco = containerco;
	var responseconid = responseconid;
	var collabcode  = collabcode;
	var myavatar    = myavatar;
	var userid      = userid;
	var namefull    = namefull;
	
	
	
	var con = $('#' + responseconid).val();
	
	if ( con.length < 1 )
	{
		return false;	
	}
	
	$('.ui-state-default').css('visibility', 'hidden');
	
	var dataargs = collabcode + '~' + myavatar + '~' + userid + '~' + con + '~' + namefull;
	
	$.post("../manager/insertcomment.cfm", { 'args': dataargs })  
	    .done(function(data) { 
		
			var xx = data.toString();
		
		        var startposition = xx.indexOf('~trimstartshere2~');
				var startposition = parseInt(startposition);
				var endposition   = xx.indexOf('~trimendshere2~'); 
				var endposition   = parseInt(endposition);	
				
				$('.ui-state-default').css('visibility', 'visible');
			  
					if (startposition >= 0 && endposition >= 0)
					{
					   var answered = xx.substring(startposition + 17, endposition);
					   
					   //var contentstring = "<tr><td><div style='background-color: #C66; width: 50px; height: 50px;'><img src='"+ myavatar +"' width='100%' height='100%'/></div></td><td><table border='1'><tr><td>Name</td></tr></table></td></tr><tr><td>&nbsp;</td><td><table border='1'><tr><td></cfoutput><p><a href='##' style='font-size: .9em'>Reply</a></p></td></tr></table></td></tr>";
	                   $('#' + containerco).prepend(answered);  
					   $('#' + responseconid).val('');  
					   
					   
					}
					else
					{ 
						alert('Internal Server Error');
						$('.ui-state-default').css('visibility', 'visible');
						return false;
					}
		
		})
		.fail(function(event, jqxhr, settings, exception) { 
		
			  alert(settings);
			  $('.ui-state-default').css('visibility', 'visible');
			  
			  return false;
		
		 });
	
	
	
}

function replyclick(containerco, responseconid, collabcode, myavatar, userid, namefull, collabcode2)
{
	var containerco = containerco;
	var responseconid = responseconid;
	var collabcode  = collabcode;
	var myavatar    = myavatar;
	var userid      = userid;
	var namefull    = namefull;
	var collabcode2 = collabcode2;
	
	
	
	//alert(containerco);
	//$('#' + containerco).prepend('<tr><td><table><tr><td>Hello</td></tr></table></td></tr>');
	
	
	var con = $('#' + responseconid).val();
	
	if ( con.length < 1 )
	{
		return false;	
	}
	
	$('.ui-state-default').css('visibility', 'hidden');
	
	var dataargs = collabcode + '~' + myavatar + '~' + userid + '~' + con + '~' + namefull + '~' + collabcode2;
	
	$.post("../manager/insertreply.cfm", { 'args': dataargs })  
	    .done(function(data) { 
		
			var xx = data.toString();
		
		        var startposition = xx.indexOf('~trimstartshere2~');
				var startposition = parseInt(startposition);
				var endposition   = xx.indexOf('~trimendshere2~'); 
				var endposition   = parseInt(endposition);	
			  
					if (startposition >= 0 && endposition >= 0)
					{
					   var answered = xx.substring(startposition + 17, endposition);
					   
					   //var contentstring = "<tr><td><div style='background-color: #C66; width: 50px; height: 50px;'><img src='"+ myavatar +"' width='100%' height='100%'/></div></td><td><table border='1'><tr><td>Name</td></tr></table></td></tr><tr><td>&nbsp;</td><td><table border='1'><tr><td></cfoutput><p><a href='##' style='font-size: .9em'>Reply</a></p></td></tr></table></td></tr>";
	                   $('#' + containerco).prepend(answered); 
					   $('#' + responseconid).val('');     
					   
					   
					}
					else
					{ 
						alert('Internal Server Error');
						$('.ui-state-default').css('visibility', 'visible');
						return false;
					}
					
					$('.ui-state-default').css('visibility', 'visible');
		
		})
		.fail(function(event, jqxhr, settings, exception) { 
		
			  alert(settings);
			 $('.ui-state-default').css('visibility', 'visible');
			  
			  return false;
		
		 });
	
	
	
}

function replynow(replyid, userid, taid)
{
	var replyid = replyid;
	var userid    = userid;
	
	
	$('#' + taid).autosize();
	$('#' + replyid).show(500);
	
	

}


function listclick(collabcode, startpoint)            
{   
	
	
	var collabcode = collabcode;
	var starting = startpoint;
	
	$('.thetopiclists').hide();  
	
	
	$('#maintabletableid').html(' ');
	
	$('#backbuttonxyzback').hide();
	$('#containerforwords').show();
	$('#listcontainerabc').hide();
	$('#loadingpleasewait').html('Loading, please wait...');
	listclick2(collabcode, startpoint);
	
}

function listclick2(collabcode, startpoint)
{
	var collabcode = collabcode;
	var starting = startpoint;
	
	
	$.post("eforumstimeline.cfm", { 'args': collabcode, 'startpoint': starting })  
	    .done(function(data) { 
		
			var xx = data.toString();
		     
		        var startposition = xx.indexOf('~trimstartshere2~');
				var startposition = parseInt(startposition);
				var endposition   = xx.indexOf('~trimendshere2~'); 
				var endposition   = parseInt(endposition);	
				
				
			  
					if (startposition >= 0 && endposition >= 0)
					{
					   var answered = xx.substring(startposition + 17, endposition);
					   
	                   $('#maintabletableid').append(answered);
					   
					   $('#loadingpleasewait').html('');
					   
					   $('#commentment').autosize();
					
					   
						   
						   	var startposition = xx.indexOf('~trimstartstatus~');
							var startposition = parseInt(startposition);
							var endposition   = xx.indexOf('~trimendstatus~'); 
							var endposition   = parseInt(endposition);	
						  
								if (startposition >= 0 && endposition >= 0)
								{
								   var answered = xx.substring(startposition + 17, endposition);
								   answered = parseInt(answered);
								   
								   if(answered == 0)
								   {
									  
									   $('.thetopiclists').show(400);
									   
									    var startposition = xx.indexOf('~trimstartcollab~');
										var startposition = parseInt(startposition);
										var endposition   = xx.indexOf('~trimendcollab~'); 
										var endposition   = parseInt(endposition);	
									  
											if (startposition >= 0 && endposition >= 0)
											{
											   var collabcode = xx.substring(startposition + 17, endposition);
											   
									   		}
											else
											{ 
												
												
												 $('#loadingpleasewait').html('');
												
												 $('.thetopiclists').show(400);
												return false;
											}
									   settozerocount(collabcode);
									   return true;
								   }
								   else
								   {
								   	
									
									    var startposition = xx.indexOf('~trimstartcollab~');
										var startposition = parseInt(startposition);
										var endposition   = xx.indexOf('~trimendcollab~'); 
										var endposition   = parseInt(endposition);	
									  
											if (startposition >= 0 && endposition >= 0)
											{
											   var collabcode = xx.substring(startposition + 17, endposition);
											   
									   		}
											else
											{ 
												//$('#backbuttonxyzback').show();
												 
												 $('#loadingpleasewait').html('');
												alert('Internal Server Error');
												$('.thetopiclists').show(400);
												return false;
											}
											
									    var startposition = xx.indexOf('~trimstartbeginn~');
										var startposition = parseInt(startposition);
										var endposition   = xx.indexOf('~trimendbegin~'); 
										var endposition   = parseInt(endposition);	
									  
											if (startposition >= 0 && endposition >= 0)
											{
											   var answered = xx.substring(startposition + 17, endposition);
											   startpoint = parseInt(answered);
											}
											else
											{ 
												//$('#backbuttonxyzback').show();
												
												 $('#loadingpleasewait').html('');
												alert('Internal Server Error');
												$('.thetopiclists').show(400);
												return false;
											}
											
										listclick2(collabcode, startpoint);
											
											
									   
								   }
								
								}
								else
								{ 
									//$('#backbuttonxyzback').show();
									
									 $('#loadingpleasewait').html('');
									alert('Internal Server Error');
									$('.thetopiclists').show(400);
									return false;
								}
									   
						   //end returned status
					   
					   
					}
					else
					{ 
						
						 $('#loadingpleasewait').html('');
						alert('Internal Server Error');
						$('.thetopiclists').show(400);
						return false;
					}
					
					
		
		})
		.fail(function(event, jqxhr, settings, exception) { 
		
			  alert(settings);
			  //$('#backbuttonxyzback').show();
			   $('#loadingpleasewait').html('');
			   $('.thetopiclists').show(400);
			   
			  return false;
		
		 });
	
		
}

function backandclean()
{
	$('#backbuttonxyzback').hide();
	//$('#containerforwords').hide();
	
	$('#listcontainerabc').html('Loading, please wait...');
	$('#listcontainerabc').show();	
	$('#maintabletableid').html(' ');
	
	
		
	
	$.post("index.cfm", { 'args': 'dataargs' })  
	    .done(function(data) { 
		
			var xx = data.toString();
		
		        var startposition = xx.indexOf('~trimstartshere2~');
				var startposition = parseInt(startposition);
				var endposition   = xx.indexOf('~trimendshere2~'); 
				var endposition   = parseInt(endposition);	
			  
					if (startposition >= 0 && endposition >= 0)
					{
					   var answered = xx.substring(startposition + 17, endposition);
					   
					   //var contentstring = "<tr><td><div style='background-color: #C66; width: 50px; height: 50px;'><img src='"+ myavatar +"' width='100%' height='100%'/></div></td><td><table border='1'><tr><td>Name</td></tr></table></td></tr><tr><td>&nbsp;</td><td><table border='1'><tr><td></cfoutput><p><a href='##' style='font-size: .9em'>Reply</a></p></td></tr></table></td></tr>";
	                   $('#listcontainerabc').html(answered); 
					  
					}
					else
					{ 
						alert('Internal Server Error. Please try again later.');
						$('#listcontainerabc').html(''); 
						
						return false; 
					}
		
		})
		.fail(function(event, jqxhr, settings, exception) { 
		
			  alert(settings);
			  $('#listcontainerabc').html(''); 
			
			  
			  return false;
		
		 });
	
}


function settozerocount(collabcode)
{
	
	var collabcode = collabcode;	
	
	$.post("../manager/settozero.cfm", { 'args': collabcode })  
	    .done(function(data) { 
		     
			return true;
		})
		.fail(function(event, jqxhr, settings, exception) { 
		
			  alert(settings);
			
			  
			  return false;
		
		 });
}